<?php
namespace app\backend\model;

class ProductCategoryModel extends \app\common\model\ProductCategory
{
    use FormDateTrait;
    public function makeFromData($default_value = [])
    {
        $data = [
            [
                'type' => 'input',
                'name' => 'title',
                'label' => '标题',
                'verify' => true,
            ], [
                'type' => 'select',
                'name' => 'nav_id',
                'label' => '所属栏目',
                'options' => NavModel::getTreeList(),
            ], [
                'type' => 'select',
                'name' => 'parent_id',
                'label' => '上级分类',
                'options' => self::getTreeList(),
            ], [
                'type' => 'number',
                'name' => 'sort',
                'label' => '排序',
            ],
        ];
        return self::mergeDefaultFormData($data, $default_value);
    }
    public static function getTreeList()
    {
        $tree = self::treeList();
        $tree_list[0] = '根分类';
        foreach ($tree as $t) {
            $tree_list[$t['id']] = $t['prefix'] . ' ' . $t['title'];
        }
        return $tree_list;
    }
    public static function getPidsById($cate_id)
    {
        $list = self::select();
        $parents_arr = getParentsList($list->toArray(), $cate_id);
        $res = [];
        foreach ($parents_arr as $v) {
            $res[] = $v['id'];
        }
        sort($res);
        return implode(",", $res);
    }
}